import { createApp } from 'vue'
import pinia from './stores'
import App from './App.vue'
import router from './router'
import drag from '@/utils/drag' //全局注册拖拽
import './utils/rem'
import '@/assets/css/common.scss'
import '@/assets/css/font.scss'
import 'element-plus/dist/index.css'
import 'animate.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'virtual:svg-icons-register'
import SvgIcon from '@/components/common/SvgIcon.vue'

// import { nextZIndex, PopupManager } from '@/utils/comm.js'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.directive('drag', drag)
// app.directive('drag', {
//   mounted: function (el, binding, vnode) {
//     const value = binding.value
//     const moveContainer =
//       (value && value.container && document.querySelector(value.container)) ||
//       document.querySelector('#map3dContainer') ||
//       document.body
//     const selector =
//       (value && value.selector && el.querySelector(value.selector)) ||
//       el.querySelector('.drag-el') ||
//       el
//     if (selector !== el) {
//       selector.classList.add('ls-draggable')
//     }
//     selector.onmousedown = function (e) {
//       el.style.transition = 'none'
//       const disx = e.clientX - el.offsetLeft
//       const disy = e.clientY - el.offsetTop
//       // const mw = moveContainer.offsetWidth
//       // const mh = moveContainer.offsetHeight
//       //自适应
//       let zoom = 1
//       zoom = document.documentElement.clientHeight / 1890
//       const mw = moveContainer.offsetWidth / zoom
//       const mh = moveContainer.offsetHeight / zoom
//       const ew = el.offsetWidth
//       const eh = el.offsetHeight
//       // 点击后将当前组件置顶
//       if (el.style.zIndex !== '' + (PopupManager.zIndex - 1)) {
//         el.style.zIndex = nextZIndex()
//       }

//       moveContainer.onmousemove = function (e) {
//         let left = e.clientX - disx
//         let top = e.clientY - disy
//         if (left < 0) {
//           left = 0
//         }
//         if (top < 0) {
//           top = 0
//         }
//         if (left > mw - ew) {
//           left = mw - ew
//         }
//         if (top > mh - eh) {
//           top = mh - eh
//         }
//         el.style.left = left + 'px'
//         el.style.top = top + 'px'
//       }
//       moveContainer.onmouseup = function (e) {
//         const left = e.clientX - disx
//         const top = e.clientY - disy
//         moveContainer.onmousemove = moveContainer.onmouseup = null
//         useDialogStore().setXY([left, top])
//         el.style.transition = 'all 0.3s'
//       }
//     }
//   }
// })
app.use(pinia)
app.use(router)
app.component('SvgIcon', SvgIcon)
app.mount('#app')
